package com.example.controller;

import com.example.service.SchoolPredictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class SchoolPredictionController {

    @Autowired
    private SchoolPredictionService schoolPredictionService;

    @GetMapping("/predict")
    public double predictScore(@RequestParam String school, @RequestParam String major) {
        try {
            return schoolPredictionService.predictScore(school, major);
        } catch (Exception e) {
            // 处理异常，这里简单地打印异常信息
            System.err.println("Error during prediction: " + e.getMessage());
            return -1; // 或者根据实际情况返回合适的错误响应
        }
    }

    @GetMapping("/evaluate")
    public ResponseEntity<?> evaluateScore(@RequestParam String school, @RequestParam String major) {
        try {
            Map<String, Double> evaluationResults = schoolPredictionService.evaluateModel(school, major);
            return ResponseEntity.ok(evaluationResults);
        } catch (Exception e) {
            // 处理异常，这里简单地打印异常信息
            System.err.println("Error during evaluation: " + e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error during evaluation");
        }
    }
}
